package com.yumeng.webapp.controller;

import com.yumeng.common.utils.JacksonUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author wxd
 * @date 2024/10/31 17:20
 */
@Controller
@RequestMapping("/page")
public class TemplatesController {

    @RequestMapping("/welcome.vw")
    public String welcome(HttpSession session, HttpServletRequest request, Model model) {
        session.setAttribute("sessionKey", "session-aa");
        request.setAttribute("requestKey", "request-bb");
        model.addAttribute("modelKey", "model-bb");

        AbstractAuthenticationToken authenticationToken = (AbstractAuthenticationToken) request.getUserPrincipal();
        model.addAttribute("remoteUser", request.getRemoteUser());
        model.addAttribute("principalName", authenticationToken.getName());
        model.addAttribute("authorities", JacksonUtils.toJsonString(authenticationToken.getAuthorities()));

        return "demo/welcome";
    }

}
